package com.situ.struts.action;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

import java.util.Map;

public class DataAction2 extends ActionSupport {

    @Override
    public String execute() throws Exception {
        System.out.println("DataAction2 execute().");
        // 方式二：通过ActionContext获取不同的Map（代表request、session、application）
        ActionContext actionContext = ActionContext.getContext();
        // Struts对HttpServletRequest对象进行封装，封装为一个Map
        // 拿到这个代表request对象的Map，通过这个Map就可以往request域对象中放值
        Map<String, Object> contextMap = actionContext.getContextMap();
        Map<String, Object> sessionMap = actionContext.getSession();
        Map<String, Object> applicationMap = actionContext.getApplication();
        sessionMap.put("request_data2", "request_data22");
        contextMap.put("session_data2", "session_data22");
        applicationMap.put("application_data2", "application_data22");
        return SUCCESS;
    }
}
